<template>
  <div class="common-layout">
    <el-container>
      <el-aside width="200px">
        <el-radio-group v-model="isCollapse" style="margin-bottom: 20px">
    <el-radio-button :label="false">expand</el-radio-button>
    <el-radio-button :label="true">collapse</el-radio-button>
  </el-radio-group>
  <el-menu
    default-active="1"
    class="el-menu-vertical-demo dark-mode"
    :collapse="isCollapse"
    :router = "true"
    @open="handleOpen"
    @close="handleClose"
  >
  <el-menu-item  @click="switchRoute('Home')">
      <el-icon><icon-menu /></el-icon>
      <template #title>首页</template>
    </el-menu-item>
    <el-menu-item  @click="switchRoute('Jiaoan')">
      <el-icon><icon-menu /></el-icon>
      <template #title>教案生成器</template>
    </el-menu-item>
    <el-menu-item index="3" disabled>
      <el-icon><icon-menu /></el-icon>
      <template #title>
        <div class="avatar-wrapper">
            <div class="nickname">{{ userInfo.username}}</div>
            <el-dropdown>
              <el-avatar
                :size="30"
                
                shape="square"
              ></el-avatar>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item @click="switchRoute('profile')"> 我的信息</el-dropdown-item>
                  
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </div>
      </template>
    </el-menu-item>
    <el-menu-item index="3" disabled>
      <el-icon><document /></el-icon>
      <template #title>Navigator Three</template>
    </el-menu-item>
    <el-menu-item index="4">
      <el-icon><setting /></el-icon>
      <template #title>Navigator Four</template>
    </el-menu-item>
  </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </div>
</template>

<style>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 180px;
  min-height: 400px;
}
</style>
<script lang="ts" setup>
import { ref } from 'vue'
import {
  Document,
  Menu as IconMenu,
  Location,
  Setting,
} from '@element-plus/icons-vue'

import router from '@/router'
import { useUserStore } from '@/stores/user'
import { toRefs } from 'vue'
import { onMounted} from 'vue'
const userStore = useUserStore()
userStore.getInfo()
const { userInfo } = toRefs(userStore)

const switchRoute = (routeName: string) => {
  router.replace({ name: routeName, params: { routeName } })
}

const isCollapse = ref(true)
const handleOpen = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}
const handleClose = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}


onMounted(() => {
  router.replace({ name: "Home"})
  console.log(userInfo.value)
  
})
</script>
